Skip to content

feat(cli): automatically accept workspace policy changes#20337

Closed
Abhijit-2592 wants to merge 1 commit into
mainfrom
abhijit-2592/hide-changed-policies-dialog
Closed

feat(cli): automatically accept workspace policy changes#20337
Abhijit-2592 wants to merge 1 commit into
mainfrom
abhijit-2592/hide-changed-policies-dialog

Conversation

@Abhijit-2592

Copy link
Copy Markdown
Contributor

Summary

Hides the PolicyUpdateDialog and automatically accepts workspace policy updates to reduce user friction. Workspace policies are now automatically accepted and loaded in both interactive and non-interactive modes.

Details

  • Updated resolveWorkspacePolicyState in packages/cli/src/config/policy.ts to automatically accept and load policies, bypassing the interactive dialog.
  • Switched from writeToStderr to debugLogger.warn for notifying about policy updates to reduce terminal noise.
  • Removed the unused interactive parameter from resolveWorkspacePolicyState and its call sites.
  • Added a TODO comment for the preserved policyUpdateConfirmationRequest infrastructure.
  • Updated unit and integration tests to reflect automatic policy acceptance.

Related Issues

Fixes #20336

How to Validate

  1. Initialize a workspace with policies.
  2. Modify a policy file in .gemini/policies/.
  3. Run the CLI in interactive mode (e.g., npm run start).
  4. Observe that the policy change is automatically accepted and loaded without showing a dialog.
  5. Verify that debugLogger.warn logs the update in debug mode.
  6. Run tests: npm test -w @google/gemini-cli -- src/config/policy.test.ts src/config/workspace-policy-cli.test.ts

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
    • Linux

@Abhijit-2592 Abhijit-2592 requested a review from a team as a code owner February 25, 2026 19:55
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Abhijit-2592, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience of the CLI by automating the acceptance of workspace policy changes. By removing the interactive dialog and automatically loading updated policies, it reduces user friction and streamlines workflows in both interactive and non-interactive environments. The change also refines how policy update notifications are handled, making them less intrusive.

Highlights

  • Automated Policy Acceptance: Workspace policy updates are now automatically accepted and loaded, eliminating the need for user interaction in both interactive and non-interactive modes.
  • Reduced Terminal Noise: Notifications for policy updates now utilize debugLogger.warn instead of writeToStderr, reducing clutter in the terminal for non-debug modes.
  • Simplified resolveWorkspacePolicyState: The interactive parameter has been removed from the resolveWorkspacePolicyState function signature and all its call sites, streamlining the function's interface.
  • Future Interactive Support Placeholder: A TODO comment has been added to preserve the infrastructure for policyUpdateConfirmationRequest, indicating potential future re-enablement of interactive policy acceptance.
  • Updated Test Suite: Unit and integration tests have been adjusted to reflect the new automatic policy acceptance behavior and the change in logging mechanism.
Changelog
  • packages/cli/src/config/config.ts
    • Removed the interactive parameter from the resolveWorkspacePolicyState function call.
  • packages/cli/src/config/policy.test.ts
    • Replaced writeToStderr import with debugLogger.
    • Removed the interactive parameter from all calls to resolveWorkspacePolicyState.
    • Updated test descriptions and assertions to verify automatic policy acceptance and the absence of policyUpdateConfirmationRequest.
    • Modified assertions to check for debugLogger.warn calls instead of writeToStderr.
  • packages/cli/src/config/policy.ts
    • Replaced writeToStderr import with debugLogger.
    • Removed the interactive parameter from the resolveWorkspacePolicyState function signature.
    • Hardcoded policyUpdateConfirmationRequest to undefined and added a TODO for future re-enablement.
    • Modified policy resolution logic to automatically accept and load policies, bypassing interactive confirmation.
    • Switched policy update warnings from writeToStderr to debugLogger.warn.
  • packages/cli/src/config/workspace-policy-cli.test.ts
    • Updated test descriptions to reflect automatic policy acceptance.
    • Modified assertions to expect policyUpdateConfirmationRequest to be undefined and mockAcceptIntegrity to be called.
    • Adjusted assertions for createPolicyEngineConfig to expect workspacePoliciesDir to be present.
Activity
  • Tests were added and updated to cover the new automatic policy acceptance logic.
  • The changes were validated on MacOS using npm run.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements automatic acceptance of workspace policy changes to reduce user friction. However, it introduces a significant security risk by automatically accepting and loading workspace policy changes without user confirmation, even in interactive mode. This bypasses a critical security control designed to prevent malicious policy injection in trusted workspaces. The notification mechanism using debugLogger.warn may not be visible to the user, increasing the risk. It is recommended to restore the interactive confirmation dialog for policy changes to ensure users remain in control of the security rules applied to their environment.

Comment on lines 94 to 109
} else {
// Non-interactive mode: warn and automatically accept/load
// Policies changed or are new.
// Automatically accept and load for now to reduce friction.
// We keep the infrastructure (PolicyUpdateConfirmationRequest etc.)
// but bypass the interactive dialog.
await integrityManager.acceptIntegrity(
'workspace',
cwd,
integrityResult.hash,
);
workspacePoliciesDir = potentialWorkspacePoliciesDir;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The PR modifies resolveWorkspacePolicyState to automatically accept and load workspace policies when they are new or have changed, bypassing the previous interactive user confirmation. While this only occurs in "trusted" folders, "trusting a folder" should not imply trusting all future, potentially malicious, changes to security policies within that folder.

An attacker who can write to the .gemini/policies/ directory of a trusted workspace (e.g., via a malicious pull request in a shared project) can now automatically inject policies that escalate their privileges, such as allowing dangerous tools (like ShellTool) to run without user confirmation.

Furthermore, the notification for this automatic acceptance has been moved from writeToStderr to debugLogger.warn, which according to the project's documentation is intercepted and routed to a debug UI, making this security-sensitive change less visible to the user in the main terminal.

References
  1. Security-sensitive settings, such as workspace policies, should not be easily overridden or automatically accepted from potentially less-trusted scopes (like a workspace) without explicit user confirmation, as this can lead to privilege escalation.
  2. Tool availability and security restrictions are managed by the policy engine. Bypassing user confirmation for policy changes undermines the policy engine's role in managing these restrictions, allowing dangerous tools to run without proper oversight.

@github-actions

Copy link
Copy Markdown

Size Change: -276 B (0%)

Total Size: 25.7 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB -276 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@Abhijit-2592

Copy link
Copy Markdown
Contributor Author

Closing in favor of #20351

@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] Hide workspace policy update dialog to reduce friction

2 participants